﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Media;
using System.Drawing.Imaging;
using System.Threading;

namespace H_GAME
{
    public class Cls_Hammer:Cls_Bio
    {
        

        #region 效果图形

        private ArrayList Z_Imgs; //行走动作
        private ArrayList D_Imgs; //蹲
        private ArrayList S_Imgs; //站立
        private ArrayList A1_Imgs; //攻击1 
        private ArrayList A2_Imgs; //攻击2
        private ArrayList A3_Imgs; //攻击3
        private ArrayList A4_Imgs; //攻击4
        private ArrayList A5_Imgs; //攻击5
        private ArrayList A6_Imgs; //攻击6
        private ArrayList JP_Imgs;//跳跃
        private ArrayList V_Imgs; //胜利
        private ArrayList DefD_Imgs; //防御蹲
        private ArrayList DefS_Imgs; //防御站
        private ArrayList DT1_Imgs; //倒下
        private ArrayList ByBitD_Imgs; //被打击
        private ArrayList ByBitS_Imgs; //被打击

        Bitmap A1_Ef_01 = new Bitmap(Application.StartupPath + "\\Pic\\Hammer1\\Ef_1.png");

        private ArrayList Effic_A3_Imgs;

        private ArrayList Effic_A5_Imgs;

        private ArrayList Effic_Def_Imgs;
        #endregion



        #region 行为
        /// <summary>
        /// 移动
        /// </summary>
        public void ImgMove()
        {
            if (Imgtype == "Z" || Imgtype == "A3")
            {
                if (Func == "L")
                {
                    X = X - Speed;
                }
                else if (Func == "R")
                {
                    X = X + Speed;

                }
                old_x = X;
            }
            else if (Imgtype == "V")
            {
                //if (Func == "L")
                //old_x = X; 
            }

        }

        /// <summary>
        /// 头像生命
        /// </summary>
        public void GetHeadLiveImg(Graphics e)
        {

            int imgtop = 10;
            if (!Isplayer)
            {
                //非玩家
                imgtop = 80;
            }
            int livePer = 20;

            Headimg = new Bitmap(Imgpath + "\\S_1.png");
            Rectangle HeadOld = new Rectangle(0, 0, Headimg.Width, Headimg.Height);
            Rectangle HeadNew = new Rectangle(124, 73, 70, 60);
            e.DrawImage(Headimg, 10, imgtop, HeadNew, GraphicsUnit.Pixel);

            #region 生命值进度条显示
            liveFrameImg = new Bitmap(Application.StartupPath + "\\Pic\\other\\HealthVial.png");
            liveImg = new Bitmap(Application.StartupPath + "\\Pic\\other\\h5.png");
            liveImgBak = new Bitmap(Application.StartupPath + "\\Pic\\other\\h4.png");

            e.DrawImage(liveFrameImg, HeadNew.Width+20, imgtop + 40, liveFrameImg.Width, liveFrameImg.Height);

            Rectangle liveframerec = new Rectangle(HeadNew.Width + 20, imgtop + 40, liveFrameImg.Width, liveFrameImg.Height);
            Rectangle Bossliverec = new Rectangle(HeadNew.Width + 20, imgtop + 40, liveImg.Width, liveImg.Height);
            int level = Live / (liveImg.Width * livePer); //生命值等级
            int severalval = Live % (liveImg.Width * livePer);//当前登记剩余生命值


            if (level >= 4)
            {
                liveImg = new Bitmap(Application.StartupPath + "\\Pic\\other\\h5.png"); //
                liveImgBak = new Bitmap(Application.StartupPath + "\\Pic\\other\\h4.png");
            }
            else if (level == 3)
            {
                liveImg = new Bitmap(Application.StartupPath + "\\Pic\\other\\h4.png"); //
                liveImgBak = new Bitmap(Application.StartupPath + "\\Pic\\other\\h3.png");
            }
            else if (level == 2)
            {
                liveImg = new Bitmap(Application.StartupPath + "\\Pic\\other\\h3.png"); //
                liveImgBak = new Bitmap(Application.StartupPath + "\\Pic\\other\\h2.png");
            }
            else if (level == 1)
            {
                liveImg = new Bitmap(Application.StartupPath + "\\Pic\\other\\h2.png"); //
                liveImgBak = new Bitmap(Application.StartupPath + "\\Pic\\other\\h1.png");
            }
            else
            {
                liveImg = new Bitmap(Application.StartupPath + "\\Pic\\other\\h1.png"); //
                liveImgBak = new Bitmap(Application.StartupPath + "\\Pic\\other\\h0.png");
            }

            Point livePotion = liveframerec.Location;
            livePotion.X = livePotion.X + 6;
            livePotion.Y = livePotion.Y + 2;

            if (level < 5)
            {
                float livewidth = (float)(severalval) / livePer;
                Bossliverec = new Rectangle(0, 0, (int)livewidth, liveImg.Height);

                //if (level > 0)
                e.DrawImage(liveImgBak, livePotion.X, livePotion.Y, liveImgBak.Width, liveImgBak.Height);

                if (Live > 0) //没有死亡
                   e.DrawImage(liveImg, livePotion.X, livePotion.Y, Bossliverec.Width, liveImgBak.Height);          
            }
            else
            {
                e.DrawImage(liveImgBak, livePotion.X, livePotion.Y, liveImgBak.Width, liveImgBak.Height);
                e.DrawImage(liveImg, livePotion.X, livePotion.Y, Bossliverec.Width, liveImgBak.Height);
            }

            Font f1 = new Font("宋体", 12, FontStyle.Bold);

            //e.DrawString("BOSS:",f1,Brushes.Yellow,liveframerec.X - 50,liveframerec.Y);
            e.DrawString(Name, f1, Brushes.Yellow, livePotion.X, imgtop+20);
            if (Live <= 0)
                Live = 0;
            e.DrawString(" 生命数值:" + Live, f1, Brushes.Yellow, liveframerec.X + 220, liveframerec.Y);
            #endregion
        }

        /// <summary>
        /// 人物动作
        /// </summary>
        /// <param name="e"></param>
        public void GetImgAction(Graphics e)
        {
            Auto();
            Actrec = new Rectangle(-1,-1,0,0);
            Defrec = new Rectangle(-1, -1, 0, 0);
            Bodyrec = new Rectangle(-1,-1,0,0);
            Destroyedval = Defaultdestroyedval;
            if (Imgtype == "Z")
            {
                //行走
                if (Imgindex < Z_Imgs.Count-1)
                {
                    Imgindex++;
                }
                else
                {
                    Imgindex = 0;
                }
                Img = new Bitmap(Imgpath + "\\" + Z_Imgs[Imgindex].ToString());
                Bodyrec = new Rectangle(X, Y, Img.Width, Img.Height);
            }
            else if (Imgtype == "S")
            {
               //站立
                if (Imgindex < S_Imgs.Count - 1)
                {
                    Imgindex++;
                }
                else
                {
                    Imgindex = 0;
                    
                }
                if (Func == "R")
                {
                    X = old_x;
                }
                Img = new Bitmap(Imgpath + "\\" + S_Imgs[Imgindex].ToString());
                Bodyrec = new Rectangle(X, Y, Img.Width, Img.Height);
            }
            else if (Imgtype == "A1")
            {
                #region 攻击1
                isfinished = false;
                Destroyedval = Destroyedval*2;
                if (Imgindex == 0)
                {
                    player = new SoundPlayer();
                    player.SoundLocation = Application.StartupPath + "\\Pic\\Hammer1\\snd\\19.wav";
                    player.Load();
                    player.Play();
                }
                //攻击类型1
                if (Imgindex < A1_Imgs.Count - 1)
                {
                    Imgindex++;
                }
                else
                {
                    Imgtype = "S";
                    Imgindex = 0;
                    isfinished = true;
                }
                X = old_x;
                Img = new Bitmap(Imgpath + "\\" + A1_Imgs[Imgindex].ToString());
                Actrec = new Rectangle(X + Img.Width / 2, Y, Img.Width / 2, Img.Height);
                Bodyrec = new Rectangle(X, Y, Img.Width/2, Img.Height);
                #endregion
            }
            else if (Imgtype == "A2")
            {
                #region 攻击2
                isfinished = false;
                Destroyedval = Destroyedval * 3;
                if (Imgindex == 0)
                {
                    player = new SoundPlayer();
                    player.SoundLocation = Application.StartupPath + "\\Pic\\Hammer1\\snd\\11.wav";
                    player.Load();
                    player.Play();
                }
                //攻击类型1
                if (Imgindex < A2_Imgs.Count - 1)
                {
                    Imgindex++;
                }
                else
                {
                    Imgtype = "S";
                    Imgindex = 0;
                    isfinished = true;

                }
                X = old_x;
                Img = new Bitmap(Imgpath + "\\" + A2_Imgs[Imgindex].ToString());
                Actrec = new Rectangle(X + Img.Width / 2, Y, Img.Width / 2, Img.Height);
                Bodyrec = new Rectangle(X, Y, Img.Width/2, Img.Height);
                #endregion
            }
            else if (Imgtype == "A3")
            {
                #region 攻击3
                //攻击类型3
                isfinished = false;
                Destroyedval = Destroyedval * 2;
                if (Imgindex == 0)
                {
                    player = new SoundPlayer();
                    player.SoundLocation = Application.StartupPath + "\\Pic\\Hammer1\\snd\\12.wav";
                    player.Load();
                    player.Play();
                }
                //攻击类型3
                Img = new Bitmap(Imgpath + "\\" + A3_Imgs[Imgindex].ToString());
                if (Imgindex < A3_Imgs.Count - 1)
                {
                    Imgindex++;
                    ImgMove();
                }
                else
                { 
                    Imgtype = "S";
                    Imgindex = 0;
                    isfinished = true;
                }
                //X = old_x;
                
                Actrec = new Rectangle(X + Img.Width/2+30, Y, Img.Width / 2, Img.Height);
                Bodyrec = new Rectangle(X+30, Y, Img.Width/2, Img.Height);
                #endregion
            }
            else if (Imgtype == "A4")
            {
                #region 攻击4
                isfinished = false;
                if (Imgindex == 0)
                {
                    player = new SoundPlayer();
                    player.SoundLocation = Application.StartupPath + "\\Pic\\Hammer1\\snd\\8.wav";
                    player.Load();
                    player.Play();
                }
                //攻击类型1
                if (Imgindex < A4_Imgs.Count - 1)
                {
                    Imgindex++;
                }
                else
                {
                    Imgtype = "S";
                    Imgindex = 0;
                    isfinished = true;

                }
                X = old_x;
                Img = new Bitmap(Imgpath + "\\" + A4_Imgs[Imgindex].ToString());
                Actrec = new Rectangle(X + Img.Width / 2 + 30, Y, Img.Width / 2, Img.Height);
                Bodyrec = new Rectangle(X+30, Y, Img.Width / 2, Img.Height);
                #endregion
            }
            else if (Imgtype == "A5")
            {
                #region 攻击5
                isfinished = false;
                if (Imgindex == 0)
                {
                    EfficDelay = 0;
                    player = new SoundPlayer();
                    player.SoundLocation = Application.StartupPath + "\\Pic\\Hammer1\\snd\\28.wav";
                    player.Load();
                    player.Play();
                }
                //攻击类型1
                if (Imgindex < A5_Imgs.Count - 1)
                {
                    Imgindex++;
                }
                else
                {
                    Imgtype = "S";
                    Imgindex = 0;
                    isfinished = true;

                }
                X = old_x;
                Img = new Bitmap(Imgpath + "\\" + A5_Imgs[Imgindex].ToString());
                Point p1 = GetMiddleP(new Rectangle(X, Y, Img.Width, Img.Height));
                Actrec = new Rectangle(p1.X - Img.Width/2-30, Y, Img.Width+60, Img.Height);
                Bodyrec = new Rectangle(p1.X-20, Y, 40, Img.Height);
                #endregion
            }
            else if (Imgtype == "A6")
            {
                #region 攻击6
                isfinished = false;
                if (Imgindex == 0)
                {
                    player = new SoundPlayer();
                    player.SoundLocation = Application.StartupPath + "\\Pic\\Hammer1\\snd\\11.wav";
                    player.Load();
                    player.Play();
                }
                //攻击类型1
                Img = new Bitmap(Imgpath + "\\" + A6_Imgs[Imgindex].ToString());
                if (Imgindex < A6_Imgs.Count - 1)
                {
                    Imgindex++;
                }
                else
                {
                    Imgtype = "D";
                    Imgindex = 0;
                    isfinished = true;

                }
                X = old_x;
                Actrec = new Rectangle(X + Img.Width / 2 + 30, Y, Img.Width / 2, Img.Height);
                Bodyrec = new Rectangle(X + 30, Y, Img.Width / 2, Img.Height);
                #endregion
            }
            else if (Imgtype == "DefS")
            {
                #region 防守站立
                isfinished = false;
                //站立防御
                if (Imgindex < DefS_Imgs.Count - 1)
                {
                    Imgindex++;
                }
                else
                {
                    Imgindex = 0;
                    isfinished = true;

                }
                if (Func == "R")
                {
                    X = old_x;
                }
                Img = new Bitmap(Imgpath + "\\" + DefS_Imgs[Imgindex].ToString());
                Defrec = new Rectangle(X + Img.Width, Y, Img.Width, Img.Height);
                //bodyrec = new Rectangle(X, Y, Img.Width, Img.Height);
                #endregion
            }
            else if (Imgtype == "DefD")
            {
                #region 下蹲防守
                isfinished = false;
                //下蹲防御
                if (Imgindex < DefD_Imgs.Count - 1)
                {
                    Imgindex++;

                }
                else
                {
                    Imgindex = 0;
                    isfinished = true;

                }

                if (Func == "R")
                {
                    X = old_x;
                }
                Img = new Bitmap(Imgpath + "\\" + DefD_Imgs[Imgindex].ToString());
                Defrec = new Rectangle(X + Img.Width, Y, Img.Width, Img.Height);
                //bodyrec = new Rectangle(X, Y, Img.Width, Img.Height);

                #endregion
            }
            else if (Imgtype == "JP")
            {
                #region 跳跃
                isfinished = false;
                if (Imgindex < JP_Imgs.Count - 1)
                {
                    Imgindex++;
                    isfinished = false;
                }
                else
                {
                    Imgindex = JP_Imgs.Count - 1;
                    //isfinished = true;
                }
                Img = new Bitmap(Imgpath + "\\" + JP_Imgs[Imgindex].ToString());
                Bodyrec = new Rectangle(X, Y, Img.Width, Img.Height);
                if (Y > (P_y - Img.Height - Maxjump))
                {
                    if (jumpdowflag == 0)
                        //上升
                        Y = Y - Downspeed;
                }
                else
                {
                    jumpdowflag = 1;
                }

                if (jumpdowflag == 1)
                {
                    if (Y < (P_y - Img.Height - Downspeed))
                    {
                        //下落
                        Y = Y + Downspeed;
                    }
                    else
                    {
                        Imgtype = "S";
                        jumpdowflag = 0;
                        player = new SoundPlayer();
                        player.SoundLocation = Application.StartupPath + "\\Pic\\Hammer1\\snd\\49.wav";
                        player.Load();
                        player.Play();
                        isfinished = true;
                    }
                }
                if (Func == "L")
                {
                    X = X - Speed * 2;
                }
                else if (Func == "R")
                {
                    X = X + Speed * 2;
                }
                old_x = X;
                #endregion
            }
            else if (Imgtype == "DT1")
            {
                #region 被击倒状态1
                isfinished = false;
                delay++;
                if (Imgindex == 0)
                {
                    player = new SoundPlayer();
                    player.SoundLocation = Application.StartupPath + "\\Pic\\Hammer1\\snd\\3.wav";
                    player.Load();
                    player.Play();
                }
                if (Imgindex < DT1_Imgs.Count - 1)
                {
                    Imgindex++;

                }
                else
                {
                    Imgindex = DT1_Imgs.Count - 1;
                    //isfinished = true;
                }
                if (delay < DT1_Imgs.Count + 19)
                {
                    Img = new Bitmap(Imgpath + "\\" + DT1_Imgs[Imgindex].ToString());
                }
                if (Y > (P_y - Img.Height - Maxdttop))
                {
                    if (jumpdowflag == 0)
                        //上升
                        Y = Y - Downspeed / 2;
                }
                else
                {
                    jumpdowflag = 1;
                }

                if (jumpdowflag == 1)
                {
                    if (Y < (P_y - Img.Height - Downspeed / 2))
                    {
                        //下落
                        Y = Y + Downspeed / 2;
                    }
                    else
                    {
                        Y = P_y - Img.Height;
                        if (Live > 0)
                        {
                            if (delay == DT1_Imgs.Count)
                            {
                                player = new SoundPlayer();
                                player.SoundLocation = Application.StartupPath + "\\Pic\\Hammer1\\snd\\49.wav";
                                player.Load();
                                player.Play();
                            }

                            if (delay >= DT1_Imgs.Count + 19)
                            {

                                Img = new Bitmap(Imgpath + "\\" + DefD_Imgs[0].ToString());
                                Y = P_y - Img.Height;
                            }

                            //延迟
                            if (delay > DT1_Imgs.Count + 30)
                            {

                                jumpdowflag = 0;
                                Imgtype = "S";
                                Imgindex = 0;
                                isfinished = true;
                                delay = 0;
                            }
                        }
                        else
                        {
                            //死亡
                            delay = 0;
                            Y = P_y - Img.Height + 30;
                        }
                    }
                }
                if (Imgindex < DT1_Imgs.Count - 1)
                {
                    if (Func == "L")
                    {
                        X = X + Speed * 2;
                    }
                    else if (Func == "R")
                    {
                        X = X - Speed * 2;
                    }
                }
                old_x = X;
                Bodyrec = new Rectangle(X, Y, Img.Width, Img.Height);
                #endregion
            }
            else if (Imgtype == "DT2")
            {
                #region 被击倒状态2
                isfinished = false;
                delay++;
                if (Imgindex == 0)
                {
                    player = new SoundPlayer();
                    player.SoundLocation = Application.StartupPath + "\\Pic\\Hammer1\\snd\\4.wav";
                    player.Load();
                    player.Play();
                }
                if (Imgindex < DT1_Imgs.Count - 1)
                {
                    Imgindex++;

                }
                else
                {
                    Imgindex = DT1_Imgs.Count - 1;
                }
                if (delay < DT1_Imgs.Count + 10)
                {
                    Img = new Bitmap(Imgpath + "\\" + DT1_Imgs[Imgindex].ToString());
                }
                else
                {
                    Img = new Bitmap(Imgpath + "\\" + DefD_Imgs[0].ToString());
                    jumpdowflag = 0;
                    Imgtype = "S";
                    Imgindex = 0;
                    isfinished = true;
                    delay = 0;
                }
                old_x = X;
                Bodyrec = new Rectangle(X, Y, Img.Width, Img.Height);
                #endregion
            }
            else if (Imgtype == "ByBitD")
            {
                #region 被打击-蹲
                isfinished = false;
                if (Imgindex == 0)
                {
                    player = new SoundPlayer();
                    player.SoundLocation = Application.StartupPath + "\\Pic\\Hammer1\\snd\\6.wav";
                    player.Load();
                    player.Play();
                }
                //下蹲防御
                if (Imgindex < ByBitD_Imgs.Count - 1)
                {
                    Imgindex++;

                }
                else
                {
                    Isbyhit = false;
                    Imgindex = 0;
                    Imgtype = "D";
                    isfinished = true;

                }
                if (Func == "R")
                {
                    X = old_x;
                }
                Img = new Bitmap(Imgpath + "\\" + ByBitD_Imgs[Imgindex].ToString());
                Bodyrec = new Rectangle(X, Y, Img.Width, Img.Height);

                #endregion
            }
            else if (Imgtype == "ByBitS")
            {
                #region 被打击-站立
                isfinished = false;
                if (Imgindex == 0)
                {
                    player = new SoundPlayer();
                    player.SoundLocation = Application.StartupPath + "\\Pic\\Hammer1\\snd\\6.wav";
                    player.Load();
                    player.Play();
                }
                //下蹲防御
                if (Imgindex < ByBitS_Imgs.Count - 1)
                {
                    Imgindex++;

                }
                else
                {
                    Isbyhit = false;
                    Imgindex = 0;
                    Imgtype = "S";
                    isfinished = true;

                }
                if (Func == "R")
                {
                    X = old_x;
                }
                Img = new Bitmap(Imgpath + "\\" + ByBitS_Imgs[Imgindex].ToString());
                Bodyrec = new Rectangle(X, Y, Img.Width, Img.Height);

                #endregion
            }
            else if (Imgtype == "V")
            {
                #region 胜利
                isfinished = false;
                if (Imgindex == V_Imgs.Count - 2)
                {
                    player=new SoundPlayer();
                    player.SoundLocation = Application.StartupPath + "\\Pic\\Hammer1\\snd\\10.wav";
                    player.Load();
                    player.Play();
                }

                //胜利
                if (Imgindex < V_Imgs.Count - 1)
                {
                    Imgindex++;
                }
                else
                {
                    //WavPlayer.Play(Application.StartupPath + "\\Hammer1\\snd\\10.wav");
                    Imgindex = V_Imgs.Count - 1;
                    isfinished = true;
                }
                X = old_x;
                Img = new Bitmap(Imgpath + "\\" + V_Imgs[Imgindex].ToString());
                #endregion
            }
            else if (Imgtype == "D")
            {
                Img = new Bitmap(Imgpath + "\\" + D_Imgs[0].ToString());
                Bodyrec = new Rectangle(X, Y, Img.Width, Img.Height);
            }
            else
            {
                Img = new Bitmap(Imgpath + "\\" + Z_Imgs[0].ToString());
                Bodyrec = new Rectangle(X, Y, Img.Width, Img.Height);

            }
            if (Func == "L")
            {
                #region 偏移量设定
                Img.RotateFlip(RotateFlipType.Rotate180FlipY);
                if (Imgtype == "V")
                {
                    //胜利姿势偏移量修正
                    Bitmap temp_Img = new Bitmap(Imgpath + "\\" + V_Imgs[0].ToString());
                    sp_width = temp_Img.Width;
                    old_x = X;
                    if (Img.Width > sp_width)
                    {
                        X = X - (Img.Width - sp_width);
                    }
                }
                else if (Imgtype == "A1")
                {
                    //战斗1姿势偏移量修正
                    Bitmap temp_Img = new Bitmap(Imgpath + "\\" + A1_Imgs[0].ToString());
                    sp_width = temp_Img.Width;
                    old_x = X;
                    int spw=System.Math.Abs(Img.Width - sp_width);
                    if (Img.Width > sp_width)
                    {
                        X = X - (Img.Width - sp_width);
                    }
                    else
                    {
                        X = X + (sp_width - Img.Width);
                    }
                    Actrec = new Rectangle(X - Img.Width / 2 + spw, Y, Img.Width / 2, Img.Height);
                    Bodyrec = new Rectangle(X + Img.Width / 2 - 35, Y, Img.Width / 2, Img.Height);
                }
                else if (Imgtype == "A2")
                {
                    //战斗2姿势偏移量修正
                    Bitmap temp_Img = new Bitmap(Imgpath + "\\" + A2_Imgs[0].ToString());
                    sp_width = temp_Img.Width;
                    old_x = X;
                    int spw = System.Math.Abs(Img.Width - sp_width);
                    if (Img.Width > sp_width)
                    {
                        X = X - (Img.Width - sp_width);
                    }
                    Actrec = new Rectangle(X - Img.Width / 2 + spw, Y, Img.Width / 2, Img.Height);
                    Bodyrec = new Rectangle(X + Img.Width/2, Y, Img.Width/2, Img.Height);
                }
                else if (Imgtype == "A4")
                {
                    //战斗2姿势偏移量修正
                    Bitmap temp_Img = new Bitmap(Imgpath + "\\" + A4_Imgs[0].ToString());
                    sp_width = temp_Img.Width;
                    old_x = X;
                    if (Img.Width > sp_width)
                    {
                        X = X - (Img.Width - sp_width);
                    }
                    Actrec = new Rectangle(X - Img.Width / 2+100, Y, Img.Width / 2, Img.Height);
                    Bodyrec = new Rectangle(X + 100, Y, Img.Width/2, Img.Height);
                }
                else if (Imgtype == "A3")
                {
                    Actrec = new Rectangle(X - Img.Width / 2+100, Y, Img.Width / 2, Img.Height);
                    Bodyrec = new Rectangle(X +100, Y, Img.Width/2, Img.Height);
                }
                else if (Imgtype == "A6")
                {
                    Bitmap temp_Img = new Bitmap(Imgpath + "\\" + A6_Imgs[0].ToString());
                    sp_width = temp_Img.Width;
                    old_x = X;
                    if (Img.Width > sp_width)
                    {
                        X = X - (Img.Width - sp_width)-20;
                    }
                    Actrec = new Rectangle(X - Img.Width / 2, Y, Img.Width / 2, Img.Height);
                    Bodyrec = new Rectangle(X + 100, Y, Img.Width / 2, Img.Height);
                }
                else if (Imgtype == "DefS")
                {
                    Defrec = new Rectangle(X, Y, Img.Width, Img.Height);
                    //bodyrec = new Rectangle(X + Img.Width / 2, Y, Img.Width / 2, Img.Height);
                }
                else if (Imgtype == "DefD")
                {
                    Defrec = new Rectangle(X, Y, Img.Width, Img.Height);
                    //bodyrec = new Rectangle(X + Img.Width / 2, Y, Img.Width / 2, Img.Height);
                }
                #endregion
            }
            else
            {
                #region 偏移量设定
                if (Imgtype == "S" && Imgtype != "D")
                {
                    //站立
                    //横坐标偏移量修正                   
                    Bitmap temp_Img = new Bitmap(Imgpath + "\\" + S_Imgs[0].ToString());
                    sp_width = temp_Img.Width;
                    old_x = X;
                    if (Img.Width > sp_width)
                    {
                        X = X - (Img.Width - sp_width);
                    }
                    
                }
                else if (Imgtype == "DefS")
                {
                    Bitmap temp_Img = new Bitmap(Imgpath + "\\" + Z_Imgs[0].ToString());
                    sp_width = temp_Img.Width;
                    old_x = X;
                    if (Img.Width > sp_width)
                    {
                        X = X + (Img.Width - sp_width);
                  
                    }
                    else
                    {
                        X = X + (sp_width - Img.Width);
                        
                    }
                    Defrec = new Rectangle(X + Img.Width, Y, Img.Width, Img.Height);
                    Defrec = new Rectangle(X, Y, Img.Width, Img.Height);
                }
                else if (Imgtype == "DefD")
                {
                    Bitmap temp_Img = new Bitmap(Imgpath + "\\" + Z_Imgs[0].ToString());
                    sp_width = temp_Img.Width;
                    old_x = X;
                    if (Img.Width > sp_width)
                    {
                        X = X + (Img.Width - sp_width);
                    }
                    else
                    {
                        X = X + (sp_width - Img.Width);
                    }
                    Defrec = new Rectangle(X + Img.Width, Y, Img.Width, Img.Height);
                    Defrec = new Rectangle(X, Y, Img.Width / 2, Img.Height);
                }
                #endregion
            }
            Img.MakeTransparent(Color.FromArgb(0, 0, 0));
            if (Imgtype != "JP" && Imgtype != "DT1" && Imgtype != "DT2")
            {
                Y = P_y - Img.Height;
            }


            e.DrawImage(Img, X, Y); //画图像

            GetEffiction(e);
        }

          /// <summary>
        /// 获取图片声音效果
        /// </summary>
        public void GetEffiction(Graphics e)
        {
            if (Imgtype == "A1")
            {
                if (Imgindex == A1_Imgs.Count - 2 ||
                    Imgindex == A1_Imgs.Count - 3)
                {
                    if (Func == "L")
                    {
                        e.DrawImage(A1_Ef_01, X - A1_Ef_01.Width+200, P_y - A1_Ef_01.Height);
                    }
                    else if (Func == "R")
                    {
                        e.DrawImage(A1_Ef_01, X + A1_Ef_01.Width - 150, P_y - A1_Ef_01.Height);
                    }
                   
                }
            }
            else if (Imgtype == "A3")
            {
                Rectangle imgrec = new Rectangle(X, Y, Img.Width, Img.Height);
                Point p1 = GetMiddleP(imgrec);
                if (EfficDelay < Effic_A3_Imgs.Count - 1)
                {
                    EfficDelay++;
                }
                else
                {
                    EfficDelay = 0;
                }

                Bitmap tempDwa = new Bitmap(Application.StartupPath + "\\Pic\\Effic\\" + Effic_A3_Imgs[EfficDelay].ToString());
                if (Func == "R")
                {

                    e.DrawImage(tempDwa, p1.X - EfficDelay * 60, P_y - tempDwa.Height);
                }
                if (Func == "L")
                {
                    tempDwa.RotateFlip(RotateFlipType.Rotate180FlipY);
                    e.DrawImage(tempDwa, p1.X + EfficDelay * 20, P_y - tempDwa.Height);
                }
            }
            else if (Imgtype == "A5")
            {
                Rectangle imgrec = new Rectangle(X, Y, Img.Width, Img.Height);
                Point p1 = GetMiddleP(imgrec);
                if (EfficDelay < Effic_A5_Imgs.Count - 1)
                {
                    EfficDelay++;
                }
                else
                {
                    EfficDelay = 0;
                }

                Bitmap tempDwa = new Bitmap(Application.StartupPath + "\\Pic\\Effic\\" + Effic_A5_Imgs[EfficDelay].ToString());
                e.DrawImage(tempDwa, p1.X - tempDwa.Width / 2, P_y - tempDwa.Height);
            }
            else if (Imgtype == "DefD" || Imgtype == "DefS")
            {
                Rectangle imgrec = new Rectangle(X, Y, Img.Width, Img.Height);
                Point p1 = GetMiddleP(imgrec);
                if (EfficDelay < Effic_Def_Imgs.Count - 1)
                {
                    EfficDelay++;
                }
                else
                {
                    EfficDelay = 0;
                }

                Bitmap tempDwa = new Bitmap(Application.StartupPath + "\\Pic\\Effic\\" + Effic_Def_Imgs[EfficDelay].ToString());
                if (Isbydef)
                {
                    if (Func == "R")
                    {
                        tempDwa.RotateFlip(RotateFlipType.Rotate180FlipY);
                        e.DrawImage(tempDwa, p1.X - tempDwa.Width / 2, P_y - Img.Height);
                    }
                    else
                    {
                        e.DrawImage(tempDwa, p1.X - tempDwa.Width / 2, P_y - Img.Height);
                    }
                }
            }
        }
   
        /// <summary>
        /// 是否被打击
        /// </summary>
        /// <param name="byhitrec">打击区域</param>
        /// <returns></returns>
        public void isBitHit(Rectangle hitrec,int destroyval)
        {
            try
            {
                if (!Isbyhit)
                {
                    hitrec.Intersect(Bodyrec);
                    if (!hitrec.IsEmpty)
                    {
                        if (Func == "L")
                        {
                            X = X + Speed * 2;
                        }
                        else if (Func == "R")
                        {
                            X = X - Speed * 2;
                        }
                        old_x = X;
                        Isbyhit = true;
                        Live = Live - destroyval;

                        if (Imgtype == "Z" || Imgtype == "S" ||
                            Imgtype == "A1" || Imgtype == "A3" ||
                            Imgtype == "A4")
                        {
                            Imgtype = "ByBitS";
                            Imgindex = 0;
                        }
                        else
                        {
                            Imgtype = "ByBitD";
                            Imgindex = 0;
                        }
                        //player.Stop();
                        player = new SoundPlayer();
                        player.SoundLocation = Application.StartupPath + "\\Pic\\Hammer1\\snd\\22.wav";
                        player.Load();
                        player.Play();

                    }
                }
              
            }
            catch
            {
                
            }
        }

        /// <summary>
        /// 是否被打击
        /// </summary>
        /// <param name="byhitrec">打击区域</param>
        /// <returns></returns>
        public bool isBitDef(Rectangle hitrec)
        {
            try
            {
                if (Imgtype == "DefS" || Imgtype == "DefD")
                {
                    Isbydef = false;
                    hitrec.Intersect(Defrec);
                    if (hitrec.IsEmpty)
                        return false;
                    else
                    {
                            if (Func == "L")
                            {
                                X = X + Speed / 2;
                            }
                            else if (Func == "R")
                            {
                                X = X - Speed / 2;
                            }
                            old_x = X;

                            player = new SoundPlayer();
                            player.SoundLocation = Application.StartupPath + "\\Pic\\Hammer1\\snd\\9.wav";
                            player.Load();
                            player.Play();
                            Isbydef = true;
                            Isbyhit = false;
                            return true;
                                 
                    }
                }
                else
                {
                    return false;
                }
                
            }
            catch
            {
                return false;
            }
        }




        public void Ini()
        {
            #region 默认参数
            X = 0;           //初始X坐标
            Imgindex = 0;    //图片索引
            Imgtype = "S";
            Func = "R";     
            Speed = 20;      //速度20
            P_y = 600;       //水平面站立位置坐标
            Maxjump = 300;   //跳跃高度
            Maxdttop = 150;  //倒地下落高度
            Downspeed = 100;
            Live = 12000;     //生命值
            Team = 2;
            Defaultdestroyedval = 40;
            Isbyhit = false;
            Isbydef = false;
            #endregion

            #region 素材
            Z_Imgs = new ArrayList();
            Z_Imgs.Add("Z_1.png");
            Z_Imgs.Add("Z_2.png");
            Z_Imgs.Add("Z_3.png");
            Z_Imgs.Add("Z_4.png");
            Z_Imgs.Add("Z_5.png");
            Z_Imgs.Add("Z_6.png");

            D_Imgs = new ArrayList();
            D_Imgs.Add("D_1.png");

            S_Imgs = new ArrayList();
            S_Imgs.Add("S_1.png");
            S_Imgs.Add("S_2.png");
            S_Imgs.Add("S_3.png");
            S_Imgs.Add("S_4.png");

            V_Imgs = new ArrayList();
            V_Imgs.Add("V_1.png");
            V_Imgs.Add("V_2.png");
            V_Imgs.Add("V_3.png");
            V_Imgs.Add("V_4.png");
            V_Imgs.Add("V_5.png");
            V_Imgs.Add("V_3.png");
            V_Imgs.Add("V_4.png");
            V_Imgs.Add("V_5.png");
            V_Imgs.Add("V_3.png");
            V_Imgs.Add("V_4.png");
            V_Imgs.Add("V_5.png");
            V_Imgs.Add("V_6.png");
            V_Imgs.Add("V_7.png");
            V_Imgs.Add("V_8.png");
            V_Imgs.Add("V_9.png");
            V_Imgs.Add("V_10.png");
            V_Imgs.Add("V_11.png");
            V_Imgs.Add("V_12.png");

            JP_Imgs = new ArrayList();
            JP_Imgs.Add("Z_2.png");
            JP_Imgs.Add("Z_3.png");
            JP_Imgs.Add("JP_1.png");
            JP_Imgs.Add("JP_2.png");
            JP_Imgs.Add("JP_1.png");
            JP_Imgs.Add("JP_2.png");
            JP_Imgs.Add("JP_1.png");
            JP_Imgs.Add("JP_2.png");


            A1_Imgs = new ArrayList();
            A1_Imgs.Add("S_1.png");
            A1_Imgs.Add("A1_1.png");
            A1_Imgs.Add("A1_2.png");
            A1_Imgs.Add("A1_3.png");
            A1_Imgs.Add("A1_4.png");
            A1_Imgs.Add("A1_5.png");
            A1_Imgs.Add("S_1.png");

            A2_Imgs = new ArrayList();
            A2_Imgs.Add("A2_1.png");
            A2_Imgs.Add("A2_2.png");
            A2_Imgs.Add("A2_3.png");
            A2_Imgs.Add("A2_4.png");
            A2_Imgs.Add("A2_5.png");
            A2_Imgs.Add("A2_6.png");

            DefD_Imgs = new ArrayList();
            DefD_Imgs.Add("A2_1.png");
            DefD_Imgs.Add("A2_6.png");
            

            DefS_Imgs = new ArrayList();
            DefS_Imgs.Add("DefS_1.png");
            DefS_Imgs.Add("DefS_2.png");

            A3_Imgs = new ArrayList();
            A3_Imgs.Add("S_1.png");
            A3_Imgs.Add("A3_1.png");
            A3_Imgs.Add("A3_2.png");
            A3_Imgs.Add("A3_3.png");
            A3_Imgs.Add("A3_4.png");
            A3_Imgs.Add("A3_5.png");
            A3_Imgs.Add("S_1.png");

            A4_Imgs = new ArrayList();
            A4_Imgs.Add("A4_1.png");
            A4_Imgs.Add("A4_2.png");
            A4_Imgs.Add("A4_3.png");
            A4_Imgs.Add("A4_4.png");


            A5_Imgs = new ArrayList();
            A5_Imgs.Add("V_1.png");
            A5_Imgs.Add("V_3.png");
            A5_Imgs.Add("V_4.png");
            A5_Imgs.Add("V_5.png");
            A5_Imgs.Add("V_3.png");
            A5_Imgs.Add("V_4.png");
            A5_Imgs.Add("V_5.png");
            A5_Imgs.Add("V_3.png");
            A5_Imgs.Add("V_4.png");
            A5_Imgs.Add("V_5.png");
            A5_Imgs.Add("V_1.png");

            A6_Imgs = new ArrayList();
            A6_Imgs.Add("0012.png");
            A6_Imgs.Add("0014.png");
            A6_Imgs.Add("0119.png");
            A6_Imgs.Add("0062.png");
         

            DT1_Imgs = new ArrayList();
            DT1_Imgs.Add("DT1_1.png");
            DT1_Imgs.Add("DT1_2.png");
            DT1_Imgs.Add("DT1_3.png");
            DT1_Imgs.Add("DT1_4.png");
            DT1_Imgs.Add("DT1_4.png");
            DT1_Imgs.Add("DT1_4.png");
            DT1_Imgs.Add("DT1_4.png");
            DT1_Imgs.Add("DT1_4.png");
            DT1_Imgs.Add("DT1_4.png");
            DT1_Imgs.Add("DT1_4.png");
            DT1_Imgs.Add("DT1_4.png");
            DT1_Imgs.Add("DT1_6.png");

            ByBitD_Imgs = new ArrayList();
            ByBitD_Imgs.Add("ByBitD_1.png");
            ByBitD_Imgs.Add("ByBitD_1.png");
          
            ByBitS_Imgs = new ArrayList();
            ByBitS_Imgs.Add("DT1_1.png");
            ByBitS_Imgs.Add("DT1_1.png");
            
            #endregion

            #region 特效图
            Effic_A3_Imgs = new ArrayList();
            Effic_A3_Imgs.Add("0146.png");
            Effic_A3_Imgs.Add("0146.png");
            Effic_A3_Imgs.Add("0147.png");
            Effic_A3_Imgs.Add("0148.png");
            Effic_A3_Imgs.Add("0149.png");

            Effic_A5_Imgs = new ArrayList();
            Effic_A5_Imgs.Add("0080.png");
            Effic_A5_Imgs.Add("0079.png");
            Effic_A5_Imgs.Add("0074.png");
            Effic_A5_Imgs.Add("0073.png");
            Effic_A5_Imgs.Add("0072.png");
            Effic_A5_Imgs.Add("0071.png");
            Effic_A5_Imgs.Add("0071.png");
            Effic_A5_Imgs.Add("0055.png");
            Effic_A5_Imgs.Add("0054.png");
            Effic_A5_Imgs.Add("0007.png");
            Effic_A5_Imgs.Add("0051.png");
            Effic_A5_Imgs.Add("0052.png");
            Effic_A5_Imgs.Add("0053.png");    

            Effic_Def_Imgs = new ArrayList();
            Effic_Def_Imgs.Add("0200.png");
            Effic_Def_Imgs.Add("0199.png");
            Effic_Def_Imgs.Add("0198.png");
            Effic_Def_Imgs.Add("0197.png");
            
            #endregion
        }

        #endregion

    }
}
